﻿// 5. Write a program to convert hexadecimal numbers to binary numbers (directly).

using System;

class HexadecimalToBinaryNumbers
{
    static void Main()
    {
        Console.Write("Enter your hexadecimal number : ");
        string hexNumber = Console.ReadLine();

        string binaryNumber = ConvertHexadecimalToBinary(hexNumber);

        Console.WriteLine("The binary representation of the hexadecimal number {0} is {1}.", hexNumber, binaryNumber);
    }

    static string ConvertHexadecimalToBinary(string hexNumber)
    {
        string binaryNumber = " ";
        string partBinary = " ";
        int length = hexNumber.Length;

        for (int i = length - 1; i >= 0; i--)
        {

            switch (hexNumber[i])
            {
                case '0': partBinary = "0000"; break;
                case '1': partBinary = "0001"; break;
                case '2': partBinary = "0010"; break;
                case '3': partBinary = "0011"; break;
                case '4': partBinary = "0100"; break;
                case '5': partBinary = "0101"; break;
                case '6': partBinary = "0110"; break;
                case '7': partBinary = "0111"; break;
                case '8': partBinary = "1000"; break;
                case '9': partBinary = "1001"; break;
                case 'A': partBinary = "1010"; break;
                case 'B': partBinary = "1011"; break;
                case 'C': partBinary = "1100"; break;
                case 'D': partBinary = "1101"; break;
                case 'E': partBinary = "1110"; break;
                case 'F': partBinary = "1111"; break;
                default: partBinary = " "; break;
            }

            binaryNumber = partBinary + " " + binaryNumber;
        }

        return binaryNumber;
    }
}
